package com.lxmes.base.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.base.domain.JcRuleFormula;
import com.lxmes.base.service.IJcRuleFormulaService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 规则公式Controller
 * 
 * @author ruoyi
 * @date 2023-01-09
 */
@RestController
@RequestMapping("/base/formula")
public class JcRuleFormulaController extends BaseController
{
    @Autowired
    private IJcRuleFormulaService jcRuleFormulaService;

    /**
     * 查询规则公式列表
     */
    @PreAuthorize("@ss.hasPermi('base:formula:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcRuleFormula jcRuleFormula)
    {
        startPage();
        List<JcRuleFormula> list = jcRuleFormulaService.selectJcRuleFormulaList(jcRuleFormula);
        return getDataTable(list);
    }

    /**
     * 导出规则公式列表
     */
    @PreAuthorize("@ss.hasPermi('base:formula:export')")
    @Log(title = "规则公式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcRuleFormula jcRuleFormula)
    {
        List<JcRuleFormula> list = jcRuleFormulaService.selectJcRuleFormulaList(jcRuleFormula);
        ExcelUtil<JcRuleFormula> util = new ExcelUtil<JcRuleFormula>(JcRuleFormula.class);
        util.exportExcel(response, list, "规则公式数据");
    }

    /**
     * 获取规则公式详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:formula:query')")
    @GetMapping(value = "/{ruleId}")
    public AjaxResult getInfo(@PathVariable("ruleId") Long ruleId)
    {
        return AjaxResult.success(jcRuleFormulaService.selectJcRuleFormulaByRuleId(ruleId));
    }

    /**
     * 新增规则公式
     */
    @PreAuthorize("@ss.hasPermi('base:formula:add')")
    @Log(title = "规则公式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcRuleFormula jcRuleFormula)
    {
        return toAjax(jcRuleFormulaService.insertJcRuleFormula(jcRuleFormula));
    }

    /**
     * 修改规则公式
     */
    @PreAuthorize("@ss.hasPermi('base:formula:edit')")
    @Log(title = "规则公式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcRuleFormula jcRuleFormula)
    {
        return toAjax(jcRuleFormulaService.updateJcRuleFormula(jcRuleFormula));
    }

    /**
     * 删除规则公式
     */
    @PreAuthorize("@ss.hasPermi('base:formula:remove')")
    @Log(title = "规则公式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds)
    {
        return toAjax(jcRuleFormulaService.deleteJcRuleFormulaByRuleIds(ruleIds));
    }
}
